#include <Arduino.h>
#include <EEPROM.h>

void eepromGetPut()
{
  unsigned int address = 0;
  String WriteVal = "EEPROM GET and PUT Test";
  EEPROM.put(address, WriteVal);   // 一次写入多个字节

  String readVal;
  EEPROM.get(address, readVal);   // 一次读取多个字节
  Serial.println(readVal);

  struct BILIBILI
  {
    String name;
    bool isActive;
    unsigned int fans;
  };

  BILIBILI myAccount = {"Lonely Binary", true, 5000U};
  address = address + sizeof(readVal);    // 加上前面已经使用的地址
  EEPROM.put(address, myAccount);

  BILIBILI myAccountRead;
  EEPROM.get(address, myAccountRead);

  Serial.println("");
  Serial.print("Bilibili Account Name : ");
  Serial.println(myAccountRead.name);
  Serial.print("Bilibili Account Status : ");
  Serial.println(myAccountRead.isActive);
  Serial.print("Number of fans : ");
  Serial.println(myAccountRead.fans);
}
void setup()
{
  Serial.begin(115200);
  // 演示5: 使用EEPROM存储任意类型数据
  eepromGetPut();
}

void loop()
{
}